import 'dart:async';

import 'package:date_format/date_format.dart';
import 'package:get/get.dart';


class TimerManager {

  TimerManager._internal();

  static final TimerManager _singleton = TimerManager._internal();

  factory TimerManager() => _singleton;

  Timer? _timer;


  RxString time = RxString('');


  void startCountDown(){
    if(_timer != null){
      if (_timer!.isActive) {
        _timer!.cancel();
        _timer = null;
      }
    }

    _timer = Timer.periodic(const Duration(seconds: 1), (timer) {
      time.value =  formatDate(DateTime.now(), [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn, ':', ss]);
      // print('time=${time.value}');
    });
  }

  void cancel(){
    if(_timer != null){
      if (_timer!.isActive) {
        _timer!.cancel();
        _timer = null;
      }
    }
  }

}
